//
//  BDHomeCellBottomView.m
//  BadBoy
//
//  Created by wen on 2017/3/13.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDHomeCellBottomView.h"
#import "BDUserModel.h"

@interface BDHomeCellBottomView ()

@property (nonatomic, strong) UIButton *zanButton;
@property (nonatomic, strong) UIButton *messageButton;
@property (nonatomic, strong) UIButton *ForwardButton;      //转发按钮
@property (nonatomic, strong) UIButton *shareButton;        //分享按钮

@end

@implementation BDHomeCellBottomView

static CGFloat buttonWidth = 0;

- (void)configeWithZanState:(BOOL)zanState zan:(NSString *)zan message:(NSString *)messaga forword:(NSString *)forword shared:(NSString *)shared{
    [_zanButton setTitle:zan forState:UIControlStateNormal];
    [_messageButton setTitle:messaga forState:UIControlStateNormal];
    [_ForwardButton setTitle:forword forState:UIControlStateNormal];
    [_shareButton setTitle:shared forState:UIControlStateNormal];
    self.zanButton.selected = zanState;
}

- (instancetype)init{
    if (self = [super init]) {
        buttonWidth = [UIScreen mainScreen].bounds.size.width / 4.0;
        [self addSubview:self.zanButton];
        [self addSubview:self.messageButton];
        [self addSubview:self.ForwardButton];
        [self addSubview:self.shareButton];
        
        for (int i = 0; i < 3; i++) {
            UIView *midLine = [[UIView alloc] init];
            midLine.backgroundColor = kBDColorGray;
            midLine.size = CGSizeMake(1, 18);
            midLine.centerX = buttonWidth * (1 + i);
            midLine.centerY = 18;
            [self addSubview:midLine];
        }
        
        for (int i = 0; i < 2; i++) {
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 1)];
            if (i == 1) {
                lineView.bottom = 36;
            }
            lineView.backgroundColor = [UIColor colorWithHexString:@"#e5e5e5"];
            [self addSubview:lineView];
        }
        
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (UIButton *)zanButton{
    if (!_zanButton) {
        self.zanButton = [[UIButton alloc]init];
        _zanButton.frame = CGRectMake(0, 0, buttonWidth, 36);
        [_zanButton setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
        [_zanButton setImage:[UIImage imageNamed:@"zan_sel"] forState:UIControlStateSelected];
        [_zanButton setTitle:@"100" forState:UIControlStateNormal];
        _zanButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        _zanButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        [_zanButton setTitleColor:kBDTimeColor forState:UIControlStateNormal];
        _zanButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [[_zanButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [BDUserModel judgeCurrentUserWithNormalBlock:^{
                if (_zanButton.selected == YES) {
                    return;
                }
                if (self.zanBlock) {
                    _zanButton.userInteractionEnabled = NO;
                    self.zanBlock(_zanButton);
                }
            }];
        }];
    }
    return _zanButton;
}

- (UIButton *)messageButton{
    if (!_messageButton) {
        self.messageButton = [[UIButton alloc]init];
        _messageButton.frame = CGRectMake(buttonWidth, 0, buttonWidth, 36);
        [_messageButton setImage:[UIImage imageNamed:@"pinglun"] forState:UIControlStateNormal];
        [_messageButton setTitle:@"  3000" forState:UIControlStateNormal];
        _messageButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        _messageButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        [_messageButton setTitleColor:kBDTimeColor forState:UIControlStateNormal];
        _messageButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [[_messageButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [BDUserModel judgeCurrentUserWithNormalBlock:^{
                if (self.pinglunBlock) {
                    self.pinglunBlock();
                }
            }];
        }];
    }
    return _messageButton;
}

- (UIButton *)ForwardButton{
    if (!_ForwardButton) {
        self.ForwardButton = [[UIButton alloc]init];
        _ForwardButton.frame = CGRectMake(buttonWidth * 2, 0, buttonWidth, 36);
        [_ForwardButton setImage:[UIImage imageNamed:@"zhuanfa"] forState:UIControlStateNormal];
        [_ForwardButton setTitle:@"  200" forState:UIControlStateNormal];
        _ForwardButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        _ForwardButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        [_ForwardButton setTitleColor:kBDTimeColor forState:UIControlStateNormal];
        _ForwardButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [[_ForwardButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [BDUserModel judgeCurrentUserWithNormalBlock:^{
                if (self.forwardBlock) {
                    self.forwardBlock();
                }
            }];
        }];
    }
    return _ForwardButton;
}

-(UIButton *)shareButton{
    if (!_shareButton) {
        self.shareButton = [[UIButton alloc]init];
        _shareButton.frame = CGRectMake(buttonWidth * 3, 0, buttonWidth, 36);
        [_shareButton setImage:[UIImage imageNamed:@"fengxiang"] forState:UIControlStateNormal];
        [_shareButton setTitle:@"  500" forState:UIControlStateNormal];
        _shareButton.imageEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
        _shareButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        [_shareButton setTitleColor:kBDTimeColor forState:UIControlStateNormal];
        _shareButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [[_shareButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            [BDUserModel judgeCurrentUserWithNormalBlock:^{
                if (self.sharedBlock) {
                    self.sharedBlock();
                }
            }];
        }];
    }
    return _shareButton;
}



@end
